package com.ruoyi.web.controller.market.risk;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.RiskCostRecordInfo;
import com.ruoyi.risk.service.IRiskCostRecordInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.RiskCostRecordInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风控消费记录Controller
 * 
 * @author ruoyi
 * @date 2023-05-28
 */
@Controller
@RequestMapping("/risk/costRecordInfo")
public class RiskCostRecordInfoController extends BaseController
{
    private String prefix = "risk/costRecordInfo";

    @Autowired
    private IRiskCostRecordInfoService riskCostRecordInfoService;

    @RequiresPermissions("risk:costRecordInfo:view")
    @GetMapping()
    public String costRecordInfo()
    {
        return prefix + "/costRecordInfo";
    }

    /**
     * 查询风控消费记录列表
     */
    @RequiresPermissions("risk:costRecordInfo:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskCostRecordInfo riskCostRecordInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = riskCostRecordInfoService.selectRiskCostRecordInfoListMap(riskCostRecordInfo);
        mapList = new RiskCostRecordInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出风控消费记录列表
     */
    @RequiresPermissions("risk:costRecordInfo:export")
    @Log(title = "风控消费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskCostRecordInfo riskCostRecordInfo)
    {
        List<RiskCostRecordInfo> list = riskCostRecordInfoService.selectRiskCostRecordInfoList(riskCostRecordInfo);
        ExcelUtil<RiskCostRecordInfo> util = new ExcelUtil<RiskCostRecordInfo>(RiskCostRecordInfo.class);
        return util.exportExcel(list, "风控消费记录数据");
    }

    /**
     * 新增风控消费记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风控消费记录
     */
    @RequiresPermissions("risk:costRecordInfo:add")
    @Log(title = "风控消费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskCostRecordInfo riskCostRecordInfo)
    {
        return toAjax(riskCostRecordInfoService.insertRiskCostRecordInfo(riskCostRecordInfo));
    }

    /**
     * 修改风控消费记录
     */
    @RequiresPermissions("risk:costRecordInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RiskCostRecordInfo riskCostRecordInfo = riskCostRecordInfoService.selectRiskCostRecordInfoById(id);
        mmap.put("riskCostRecordInfo", riskCostRecordInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存风控消费记录
     */
    @RequiresPermissions("risk:costRecordInfo:edit")
    @Log(title = "风控消费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskCostRecordInfo riskCostRecordInfo)
    {
        return toAjax(riskCostRecordInfoService.updateRiskCostRecordInfo(riskCostRecordInfo));
    }

    /**
     * 删除风控消费记录
     */
    @RequiresPermissions("risk:costRecordInfo:remove")
    @Log(title = "风控消费记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskCostRecordInfoService.deleteRiskCostRecordInfoByIds(ids));
    }
}
